package homework01;

import java.util.LinkedHashMap;
import java.util.Map;

public class StudentItemDao {
    //数据库
    static Map<Integer,StudentItem> map = new LinkedHashMap<Integer,StudentItem>();
    //初始化
    static {
        StudentItem si1 = new StudentItem(11,"马牛逼",21);
        StudentItem si2 = new StudentItem(12,"二愣子",25);
        StudentItem si3 = new StudentItem(13,"张德帅",23);
        StudentItem si4 = new StudentItem(14,"黄家驹",28);
        map.put(si1.getId(), si1);
        map.put(si2.getId(), si2);
        map.put(si3.getId(), si3);
        map.put(si4.getId(), si4);
    }

    public StudentItem queryById(int id) {
        return map.get(id);
    }

    /**
     * 添加
     * @param si
     * @return
     */
    public int insert(StudentItem si) {
        int flag = -1;
        map.put(si.getId(), si);
        flag = 1;
        return flag;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int delete(int id) {
        int flag = -1;
        map.remove(id);
        flag = 1;
        return flag;
    }

    /**
     * 查看信息
     * @return
     */
    public Map<Integer,StudentItem> queryAll() {
        return map;
    }

}
